package edu.uoc.tdp.pac4.client.stats;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import edu.uoc.tdp.pac4.common.util.LanguageUtils;

public class StatTeacherTwoModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;

	protected Vector<String> listHeaders = new Vector<String>();

	protected List<StatResultData> results = new ArrayList<StatResultData>();

	public StatTeacherTwoModel() {

	}

	public StatTeacherTwoModel(List<StatResultData> resRqstList) {
		setHeader();
		results = resRqstList;
	}

	protected void setHeader() {
		listHeaders.add(LanguageUtils.getMessage("client.statistics.nomcurs"));
		listHeaders.add(LanguageUtils.getMessage("client.statistics.datainici"));
		listHeaders.add(LanguageUtils.getMessage("client.statistics.datafi"));
		listHeaders.add(LanguageUtils.getMessage("client.statistics.assistrequerida"));
		listHeaders.add(LanguageUtils.getMessage("client.statistics.assistactual"));
		listHeaders.add(LanguageUtils.getMessage("client.statistics.asssitDif"));
		
	}

	public String getColumnName(int col) {
		return ((String) listHeaders.get(col));
	}

	public int getColumnCount() {
		return listHeaders.size();
	}

	public int getRowCount() {
		if (results != null)
			return results.size();
		else
			return 0;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		StatResultData res = null;
		if (results != null) {
			res = (StatResultData) results.get(rowIndex);

			switch (columnIndex) {
			case 0:
				return res.getNomCurs()!=null?res.getNomCurs():"nomCurs";
			case 1:
				return res.getDataInici()!=null?res.getDataInici():"dataIni";
			case 2:
				return res.getDataFi()!=null?res.getDataFi():"dataFi";
			case 3:
				return res.getAssistReq() + " %";
			case 4:
				return res.getAssistActual() + " %";
			case 5:
				float assist = 0;
				if(res.getAssistActual() != null && res.getAssistReq() != null){
					assist = (res.getAssistActual() - res.getAssistReq());
				}
				return assist + " %";
			}
		}
		return res;
	}

	public boolean isCellEditable(int fila, int columna) {
		return (false);
	}
}
